<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id');
            $table->string('order_id')->unique()->index();
            $table->enum('payment_method', ['alipay', 'wechat', 'balance']);
            $table->string('payment_id')->unique()->nullable()->comment("支付平台订单号");
            $table->enum('status', ['pending', 'completed'])->default('pending');
            $table->timestamp('paid_at')->nullable();
            $table->foreignId('plan_id')->nullable();
            $table->string('coupon_code_id')->nullable();
            $table->integer('coupon_discount')->default(0)->nullable();
            $table->integer('amount')->comment('actual amount, the amount after coupon discount');
            $table->enum('order_type', ['buy_plan', 'balance_recharge', 'balance_withdraw'])->default('buy_plan');
            $table->string('remark')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('orders');
    }
};
